import java.util.Comparator;

public class Point implements Comparable<Point> {

	private int x;
	private int y;

	public Point(int x, int y) {
		this.x = x;
		this.y = y;
	}

	public Point() {
		this(0, 0);
	}

	public void draw() {
		StdDraw.text(x - 400, y + 1000, toString());
		StdDraw.circle(x, y, 100);
	}

	public void drawTo(Point other) {
		StdDraw.line(this.x, this.y, other.x, other.y);
	}

	public final Comparator<Point> SLOPE_ORDER = new Comparator<Point>() {
		@Override
		public int compare(Point other1, Point other2) {
			return Double.compare(slopeTo(other1), slopeTo(other2));
		}
	};

	public double slopeTo(Point other) {
		double slope = 0;
		if (this.compareTo(other) == 0) {
			slope = Double.NEGATIVE_INFINITY;
		} else if (this.x == other.x) {
			slope = Double.POSITIVE_INFINITY;
		} else if (this.y == other.y) {
			slope = 0;
		} else {
			slope = (double) (this.y - other.y) / (this.x - other.x);
		}
		return slope;
	}

	@Override
	public int compareTo(Point other) {
		return compareToInternal(other);
	}

	private int compareToInternal(Point other) {

		if (this.y == other.y) {
			if (this.x == other.x) {
				return 0;
			} else if (this.x < other.x) {
				return -1;
			}
		} else if (this.y < other.y) {
			return -1;
		}
		return 1;
	}

	@Override
	public String toString() {
		return "(" + x / 1000 + "," + y / 1000 + ")";
	}
}
